package com.android.readcard.utils;

import android.graphics.Bitmap;

import com.android.readcard.bean.CardData;
import com.android.readcard.bean.ReadCardInfo;


public class UploadCardUtils {

    private static Bitmap photo;
    private static String name, sex, nation, id_num, address, sign_office, photoHeard, to, from, born;
    private static String birth_year, birth_month, birth_day, sign_data, bluetoothType;

    /**
     * 上传身份证信息
     */
    public static ReadCardInfo getCardInfo(String bluetoohName, String maddress,
                                           String mphotoHeard, String msex, String mid_num,
                                           String mnation, String msign_office, String mto, String mname,
                                           String mfrom, String mborn, String msign_data, String mbirth_year,
                                           String mbirth_month, String mbirth_day, Bitmap mphoto) {
        photo = mphoto;
        address = maddress.replaceAll(" ", "");
        to = mto.replaceAll(" ", "");
        from = mfrom.replaceAll(" ", "");
        born = mborn.replaceAll(" ", "");
        photoHeard = mphotoHeard.replaceAll(" ", "");
        sex = msex.replaceAll(" ", "");
        id_num = mid_num.replaceAll(" ", "");
        nation = mnation.replaceAll(" ", "");
        sign_office = msign_office.replaceAll(" ", "");
        name = mname.replaceAll(" ", "");
        sign_data = msign_data.replaceAll(" ", "");
        birth_year = mbirth_year.replaceAll(" ", "");
        birth_month = mbirth_month.replaceAll(" ", "");
        birth_day = mbirth_day.replaceAll(" ", "");


        String idPath = ImageTools.savePhotoToSDCard(photo, GlobalPathUtils.getFileDirectory()
                + GlobalPathUtils.STR_PATH, "/touxiang.jpg").getPath(); // 头像保存路径

        ReadCardInfo mCardInfo = new ReadCardInfo();
        mCardInfo.setBluetoohName(bluetoohName);
        mCardInfo.setAddress(address);
        mCardInfo.setSex(sex);
        mCardInfo.setId_num(id_num);
        mCardInfo.setNation(nation);
        mCardInfo.setSign_office(sign_office);
        mCardInfo.setName(name);
        mCardInfo.setSign_data(sign_data);
        mCardInfo.setBirth_year(birth_year);
        mCardInfo.setBirth_month(birth_month);
        mCardInfo.setBirth_day(birth_day);
        mCardInfo.setIdPath(idPath);
        mCardInfo.setTo(to);
        mCardInfo.setFrom(from);
        mCardInfo.setBorn(born);
        mCardInfo.setPhotoHeard(photoHeard);

        return mCardInfo;

    }

    /**
     * 读卡返回Data,要转化为json格式,网络上传
     */
    public static CardData getData(String bluetoothType, String maddress,
                                   String mphotoHeard, String msex, String mid_num,
                                   String mnation, String msign_office, String mto, String mname,
                                   String mfrom, String mborn, String msign_data, String mbirth_year,
                                   String mbirth_month, String mbirth_day, Bitmap mphoto) {
        photo = mphoto;
        bluetoothType = bluetoothType;
        address = maddress.replaceAll(" ", "");
        to = mto.replaceAll(" ", "");
        from = mfrom.replaceAll(" ", "");
        born = mborn.replaceAll(" ", "");
        photoHeard = mphotoHeard.replaceAll(" ", "");
        sex = msex.replaceAll(" ", "");
        id_num = mid_num.replaceAll(" ", "");
        nation = mnation.replaceAll(" ", "");
        sign_office = msign_office.replaceAll(" ", "");
        name = mname.replaceAll(" ", "");
        sign_data = msign_data.replaceAll(" ", "");
        birth_year = mbirth_year.replaceAll(" ", "");
        birth_month = mbirth_month.replaceAll(" ", "");
        birth_day = mbirth_day.replaceAll(" ", "");

        // 将参数封装进Data对象，然后转成json
        CardData cardDataInfo = new CardData();
        cardDataInfo.setAddress(address);
        cardDataInfo.setPhoto(photoHeard); // 图片
        cardDataInfo.setSex(sex);
        cardDataInfo.setIdcardno(id_num);
        cardDataInfo.setNation(nation); // 民族
        cardDataInfo.setGrantdept(sign_office);  // 签发机关
        cardDataInfo.setTo(to); // 有效期的开始时间
        cardDataInfo.setuSAMID("00000");
        cardDataInfo.setName(name);  // 名字
        cardDataInfo.setForm(from); // 有效期的截止日期
        cardDataInfo.setBorn(born); // 生日
        cardDataInfo.setReaderCode(bluetoothType);

        return cardDataInfo;
    }

    public static String getChuanMa(String bleNum, String bleId) {
        String chuanMa = "{\"reader_name\":\"" + bleNum + "\",\"reader_id\":\"" + bleId + "\"}";
        return chuanMa;
    }

}
